<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>4_展开运算符</title>
</head>
<body>
  <script type="text/javascript">
    let arr1 = [1,3,5,7,9]
    let arr2 = [2,4,6,8,10]

    // 展开数组
    console.log(...arr1);
    // 连接数组
    let arr3 = [...arr1, ...arr2]
    console.log(arr3);
    // 函数型参，用于接收参数
    function sum(...nums) {
      return nums.reduce((pre, cur) => {
        return pre + cur
      })
    }
    console.log(sum(arr1));
    // 构建字面两对象
    const p = {name: 'tom', age: 20}
    const p1 = {...p}
    console.log(p1);
    p.name = 'kat'
    console.log(p);
    console.log(p1);
    // 合并
    let p3 = {...p1, address: '1111', phone: '111222'}
    console.log(p3);
    // 4_展开运算符.html:35 Uncaught TypeError: Spread syntax requires ...iterable[Symbol.iterator] to be a function
    // 原生不支持直接...展开，但是外面接{}就是原生支持的语法
    // console.log(...p);
  </script>
</body>
</html>